/** Copyright 2014, Ross Mahony. Some rights reserved. See COPYING. */
package models

import play.api.db.slick.Config.driver.simple._
import scala.slick.lifted.Tag

case class MeterType(id: Option[Long], code: String, description: String)

/** MeterType entity. */
class MeterTypeTbl(tag: Tag) extends Table[MeterType](tag, "MTR_TYP") {

  def id = column[Long]("ID", O.PrimaryKey, O.AutoInc)
  def code = column[String]("CD", O.NotNull)
  def description = column[String]("DESCR", O.Nullable)
  def * = (id.?, code, description) <> (MeterType.tupled, MeterType.unapply _)
}

/** MeterType DAO */
object MeterTypeDAO {
  val meterTypes = TableQuery[MeterTypeTbl]
  
 /**
  * Retrieve a [[models.MeterType]] by the id
  *
  * @param id
  */
  def findById(id: Long)(implicit s: Session): Option[MeterType] =
  meterTypes.where(_.id === id).firstOption


 /** Count all meterTypes */
  def count(implicit s: Session): Int =
  Query(meterTypes.length).first

 /**
  * Insert a new [[models.MeterType]]
  * @param meterType
  */
  def insert(meterType: MeterType)(implicit s: Session) {
    meterTypes.insert(meterType)
  }

 /**
  * Insert a new [[models.MeterType]] by ignoring auto inc column
  *
  * @param meterType
  */
  def forceInsert(meterType: MeterType)(implicit s: Session) {
    meterTypes.forceInsert(meterType)
  }

 /** Delete all meterTypes */
  def deleteAll(implicit s: Session) {
    meterTypes.delete
  }

}
